﻿using System;
using System.Net;

namespace MiFi.Sample {
	class Program {
		static void Main(string[] args) {
			IPAddress ip = null;
			while (ip == null) {
				Console.Write("Enter device IP: ");
				IPAddress.TryParse(Console.ReadLine(), out ip);
			}

			MiFiDevice device = new MiFiDevice(ip);

			MiFiStatus status = device.GetStatus();
			WL("Network Found:          {0}", status.NetworkFound);
			WL("Network:                {0} {1}", status.NetworkName, status.NetworkTechnology);
			WL("Signal Strength:        {0}", status.SignalStrength);
			WL("Connection Status:      {0}", status.ConnectionStatus);
			WL("Roaming:                {0}", status.RoamingStatus);
			WL("Activation Status:      {0}", status.ActivationStatus);
			WL("Data Received:          {0} MB", status.DataReceived);
			WL("Data Transmitted:       {0} MB", status.DataTransmitted);
			WL("Charge:                 {0} ({1})", status.Charge, status.Charge == MiFiStatus.MAX_CHARGE ? "Fully Charged" : (status.Charging ? "Charging" : "Unplugged"));
			WL("IP Address:             {0}", status.IPAddress);
			WL("Gateway:                {0}", status.Gateway);
			WL("Mask:                   {0}", status.Mask);
			WL("DNS:                    {0}", status.Dns);
			WL("Session time:           {0}", status.SessionTime);
			WL("WiFi Clients:           {0}", status.Clients);
			WL("Firmware Update Status: {0}", status.FirmwareUpdateStatus);
			WL("MSL:                    {0}", status.MasterSubsidyLock);
			WL("PRL Update Status:      {0}", status.PrlUpdateStatus);

			Console.WriteLine();

			MiFiLocation location = device.GetLocation();
			WL("Has Fix:                        {0}", location.HasFix);
			WL("Location (lon, lat):            {0}, {1}", location.Longitude, location.Latitude);
			WL("Altitude:                       {0} meters", location.Altitude);
			WL("Angle of Uncertainty:           {0} radians", location.AngleOfUncertainty);
			WL("Heading:                        {0} degrees", location.Heading);
			WL("Horizontal Velocity:            {0} meters/sec", location.HorizontalVelocity);
			WL("Perpendicular Uncertainty:      {0} meters", location.PerpendicularUncertainty);
			WL("Standard Dev. Uncertainty:      {0} meters", location.StandardDeviationUncertainty);
			WL("Timestamp:                      {0}", location.Timestamp);
			WL("Vertical Uncertainty:           {0} meters", location.VerticalUncertainty);
			WL("Vertical Velocity:              {0} meters/sec", location.VerticalVelocity);
			WL("Horizontal Accuracy:            {0} meters", location.HorizontalAccuracy);
			WL("Vertical Accuracy:              {0} meters", location.VerticalAccuracy);

			Console.ReadKey();
		}

		static void WL(string format, params object[] args) {
			Console.WriteLine(string.Format(format, args));
		}
	}
}
